package com.itly.rwmlj.service.Impl;

import com.itly.rwmlj.dao.UserDao;
import com.itly.rwmlj.pojo.User;
import com.itly.rwmlj.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: 罗言
 * @Version: 1.0
 * @Date: 2023-11-21-12:47
 * @Description:
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public boolean login(User user) {
        return isEmpty(user) && userDao.login(user) != null;
    }

    @Override
    public boolean insert(User user) {
        if (!isEmpty(user)) return false;
        user.setUserName(user.getUserName().trim());
        user.setUserPws(user.getUserPws().trim());
        boolean flag = login(user);
        return !flag && userDao.insert(user) > 0;
    }

    public boolean isEmpty(User user){
        try {
            if("".equals(user.getUserName())) return false;
            if("".equals(user.getUserPws())) return false;
            user.setUserName(user.getUserName().trim());
            user.setUserPws(user.getUserPws().trim());
        } catch (Exception e) {
            return false;
        }
        return true;
    }

}
